package com.fxu.tpl.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fxu.framework.core.base.Cascade;
import com.fxu.framework.core.enums.EnumValid;
import com.fxu.framework.core.enums.StatusEnum;
import com.fxu.framework.core.sql.SEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.io.Serializable;

import static com.baomidou.mybatisplus.annotation.FieldFill.INSERT;
import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;

/***
 * <p>fxu</p>
 * 测试表：[test]实体类
 * @author fxu
 * @version 2021-03-16
 * Entity 需要有 @TableName("test") 和 继承 SEntity[Test]
 ***/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="Test", description="测试")
@TableName("test")
public class Test extends SEntity<Test> implements Serializable {
/*=== 自动生成代码 开始 ===*/
	private static final long serialVersionUID = 232341577089909949L;

	// id 需要有 @TableId
	@TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "自增ID")
    private Long id;

    @ApiModelProperty(value = "名字")
    private String name;

    @ApiModelProperty(value = "测试信息ID")
    private Long testInfoId;

    // status 需要有默认值 default 1
    @EnumValid(target = StatusEnum.class, message = "状态值错误")
    private Integer status;

    // version 需要有默认值 default 1
    // create_time DEFAULT CURRENT_TIMESTAMP
    // update_time DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    @TableField(fill = UPDATE, update = "%s+1")
    private Integer version;

    @TableField(exist = false)
    @Cascade(thisField = "id", linkField = "testId", save = true)
    private TestInfo testInfo;

    @TableField(exist = false)
    @Cascade(thisField = "id", linkField = "testId", save = true)
    private java.util.List<TestItem> itemList;
/*=== 自动生成代码 结束 ===*/
}
